package com.daxt.utils;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;

import org.apache.commons.io.FileUtils;
import org.springframework.beans.factory.annotation.Value;

public class FileCopyUtil {
//	@Value(value = "${systemConfig.ossDir}")
//	private String ossDir;
	
	public static String uploadFile(String bucketName, String objectName,InputStream input,String dir) throws IOException {
		try {
			
			FileUtils.copyToFile(input,new File(dir+"/"+bucketName+"/"+objectName));
			return bucketName+"/"+objectName;
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	
	}
	
	public static String uploadFile(String bucketName, String objectName,String filePath,String dir) {
		InputStream input=null;
		try {
			input=new FileInputStream(dir+"/"+objectName);
			FileUtils.copyToFile(input,new File(dir+"/"+objectName));
			return bucketName+"/"+objectName;
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}finally {
			if(input!=null)
				try {
					input.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
		}
	}


}
